Ignore Cargo.lock for libs in `cargo-new`
authorAlex Crichton <alex@alexcrichton.com>
Mon, 4 Aug 2014 14:45:25 +0000 (07:45 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 4 Aug 2014 14:46:03 +0000 (07:46 -0700)
The lockfile should only be checked in for bins, not libs.

Closes #304

src/cargo/ops/cargo_new.rs

index 51e8255d44b6f090113c217d832efcb4069f21e0..c9f1ccdf0071cd8104c08b8fbea21bf7f3017a92 100644 (file)
@@ -32,7 +32,11 @@ fn mk(path: &Path, name: &str, opts: &NewOptions) -> CargoResult<()> {
 
     if opts.git {
         try!(git!("init", path));
-        try!(File::create(&path.join(".gitignore")).write(b"/target\n"));
+        let mut gitignore = "/target\n".to_string();
+        if !opts.bin {
+            gitignore.push_str("/Cargo.lock\n");
+        }
+        try!(File::create(&path.join(".gitignore")).write(gitignore.as_bytes()));
     } else {
         try!(fs::mkdir(path, io::UserRWX));
     }